<jsp:useBean id="sessiondata" class="bibbletex.models.SessionData"
	scope="session" />

<%@ page
	import="bibbletex.models.*,java.util.UUID,java.util.List"
	import="bibbletex.views.CollaborationView,bibbletex.controllers.CollaborationController"
	import="bibbletex.helpers.BibtexFormat, bibbletex.helpers.FileHelper" %>	

<%!
	String page_title = new String("Export references");
	String onloadjsfunction = "";
	boolean show_title = true;
%>
<%
	String id_parameter = request.getParameter("cid");
	String file_parameter = request.getParameter("file");
	Collaboration c = null;
	
	if (id_parameter == null)
	{
		if (sessiondata.collaboration != null)
			c = sessiondata.collaboration;
	}
	else
	{
		c = CollaborationController.load(id_parameter);
		sessiondata.collaboration = c;
	}
	
	if (c != null && file_parameter != null){
		FileHelper.writeFile(c, response);
	} else {
%>
<%@ include file="/header.jsp"%>

<% if (c != null) { %>
<p>Download the references as a file: <a href="export.jsp?file">Download</a></p>
<label for="bibtexcode">BibTeX-formatted references</label>
<textarea name="bibtexcode" rows="10">
<% for (Reference r : sessiondata.collaboration.getReferences()) { %>
<%=BibtexFormat.toString(r) %>
<% } %>
</textarea>

<% } else { %>

<p>Unable to load Collaboration</p>

<% } %>

<%@ include file="/footer.jsp"%>
<% } %>